import { MessageType } from 'antd/es/message/interface';
import { ArgsProps } from 'antd/lib/message';
import { message } from 'antd';
import * as React from 'react';

export const MSG = {
  SELECT_ERROR: '查询失败，请联系管理员',
  DETAIL_TITLE: '详情',
  UPDATE_TITLE: '编辑',

  UPDATE_SUCCESS: '修改成功',
  UPDATE_LOADING: '修改中...',
  UPDATE_ERROR: '修改失败，请联系管理员',

  DELETE_SUCCESS: '删除成功',
  DELETE_LOADING: '删除中...',
  DELETE_ERROR: '删除失败，请联系管理员',
  DELETE_TIP: '确认要删除该记录吗?',

  INSERT_TITLE: '新增',
  INSERT_SUCCESS: '新增成功',
  INSERT_LOADING: '新增中...',
  INSERT_ERROR: '新增失败，请联系管理员',

  RENEW_SUCCESS: '更新成功',
  RENEW_LOADING: '更新中...',
  RENEW_ERROR: '更新失败，请联系管理员',
};

export const StrUtil = {
  COMMIT: ',',
  SLASH: '/',
  DASHED: '-',
  DOT: '.',
  UNDERLINE: '_',
} as const;

type MsgApiFun = (content: React.ReactNode, config?: Omit<ArgsProps, 'content'>) => MessageType;

interface MsgApiType {
  open: MsgApiFun;
  success: MsgApiFun;
  error: MsgApiFun;
  info: MsgApiFun;
  warning: MsgApiFun;
  loading: MsgApiFun;
}

export const msgApi: MsgApiType = {
  open: (content, config) =>
    message.open({
      content,
      ...config,
    }),
  success: (content, config) =>
    message.open({
      ...config,
      type: 'success',
      content,
    }),
  error: (content, config) =>
    message.open({
      ...config,
      type: 'error',
      content,
    }),
  info: (content, config) =>
    message.open({
      ...config,
      type: 'info',
      content,
    }),
  warning: (content, config) =>
    message.open({
      ...config,
      type: 'warning',
      content,
    }),
  loading: (content, config) =>
    message.open({
      ...config,
      type: 'loading',
      content,
    }),
};
